<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/mall-common :: common_head(~{::title},~{::link},~{::script})">
    <title>NeuMall</title>
    <link rel="stylesheet" href="/styles/mall/order-pay.css">
    <script src="/javascript/mall/order-pay.js" type="text/javascript"></script>
</head>
<body>
<div th:replace="common/mall-common::mall-header"></div>

<div class="container">
    <form th:action="@{/changePassword}" method="post" style="margin-top: 40px" class="form">
        <div class="input-group">
            <label for="oldPassword">旧密码</label>
            <input type="text" class="form-control" id="oldPassword" name="oldPassword">
            <span class="invalid-feedback" id="errorPwd" style="display: none">
                密码错误！
            </span>
        </div>
        <div class="input-group">
            <label for="newPassword">新密码</label>
            <input type="text" class="form-control" id="newPassword" name="newPassword">
            <span class="invalid-feedback" id="emptyPwd" style="display: none">
                密码不能为空！
            </span>
        </div>
        <div class="input-group">
            <label for="checkPassword">确认密码</label>
            <input type="text" class="form-control" id="checkPassword" name="checkPassword">
            <span class="invalid-feedback" id="errorChecked" style="display: none">
                两次输入密码不一致！
            </span>
        </div>
        <input type="submit" value="修    改" class="btn btn-outline-primary btn-lg" style="margin-top: 20px">
        <a th:href="@{/}" class="btn btn-outline-secondary btn-lg" style="margin-left: 40px; margin-top: 20px">返&nbsp;&nbsp;&nbsp;&nbsp;回</a>
    </form>
</div>

<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
    $(function () {
        $("#oldPassword").blur(
            function () {
                $.post("/checkPassword",
                    {
                        password: $(this).val()
                    },
                    function (data) {
                        if (data == "0") {
                            $("#oldPassword").removeClass("is-valid");
                            $("#oldPassword").addClass("is-invalid");
                            $("#errorPwd").show();
                        } else {
                            $("#oldPassword").removeClass("is-invalid");
                            $("#oldPassword").addClass("is-valid");
                            $("#errorMsg").hide();
                        }
                    })
            }
        );
        $("#newPassword").blur(function () {
            if ($("#newPassword").val() == '') {
                $("#newPassword").removeClass("is-valid");
                $("#newPassword").addClass("is-invalid");
                $("#emptyPwd").show();
            } else {
                $("#newPassword").removeClass("is-invalid");
                $("#newPassword").addClass("is-valid");
                $("#emptyPwd").hide();
            }
            if ($("#checkPassword").val() != $("#newPassword").val()) {
                    $("#checkPassword").removeClass("is-valid");
                    $("#checkPassword").addClass("is-invalid");
                    $("#errorChecked").show();
            } else {
                if ($("#checkPassword").val() == '') {
                    $("#checkPassword").removeClass("is-valid");
                    $("#checkPassword").removeClass("is-invalid");
                    $("#errorChecked").hide();
                } else {
                    $("#checkPassword").removeClass("is-invalid");
                    $("#checkPassword").addClass("is-valid");
                    $("#errorChecked").hide();
                }
            }
        });
        $("#checkPassword").blur(function () {
            if ($("#checkPassword").val() != $("#newPassword").val()) {
                $("#checkPassword").removeClass("is-valid");
                $("#checkPassword").addClass("is-invalid");
                $("#errorChecked").show();
            } else {
                if ($("#checkPassword").val() == '') {
                    $("#checkPassword").removeClass("is-valid");
                    $("#checkPassword").removeClass("is-invalid");
                    $("#errorChecked").hide();
                } else {
                    $("#checkPassword").removeClass("is-invalid");
                    $("#checkPassword").addClass("is-valid");
                    $("#errorChecked").hide();
                }
            }
        })
    });
</script>

<div th:replace="common/mall-common::mall-footer"></div>
</body>
</html>